package com.wyh.service.serviceImpl.gfiveImpl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyh.common.result.Result;
import com.wyh.domain.po.gfive.Template;
import com.wyh.service.gfive.TemplateService;
import com.wyh.mapper.gfivemapper.TemplateMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KmJHHhhhR
 * @description 针对表【template(通知模板表)】的数据库操作Service实现
 * @createDate 2024-05-20 15:03:04
 */
@Service
@Slf4j
public class TeplateServcieImpl extends ServiceImpl<TemplateMapper, Template> implements TemplateService {

    @Resource
    private TemplateMapper templateMapper;

    /**
     * 分页返回全部模板信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Result selectlPageAll(Integer pageNum, Integer pageSize) {
        Page<Template> templatePage = templateMapper.selectPage(new Page<>(pageNum, pageSize), null);

        List<Template> records = templatePage.getRecords(); //获取分页的数据
        long total = templatePage.getTotal(); //获取总条数
        return Result.success(records, total);
    }

    @Override
    public Result deleById(Integer id) {
        int i = templateMapper.deleteById(id);
        if(i>0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

}



